package com.laihui.adapters;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.laihui.activity.R;
import com.laihui.entity.LoanBean;
import com.laihui.entity.LoanList;
import com.laihui.model.Invest;

import java.text.DecimalFormat;

/**
 * Created by ST on 2017/7/22.
 */

public class LoanRecordAdapter extends RecyclerArrayAdapter<LoanBean> {
    public LoanRecordAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent ,int viewType) {
        return new LoanRecordViewHolder(parent);
    }


    class LoanRecordViewHolder extends BaseViewHolder<LoanBean> {
        private TextView tv_loan_name,tv_loan_progress,tv_loan_money,borrow_last_money,tv_loan_apr,tv_time_limit;
        private ProgressBar pb;



        public LoanRecordViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_invest_fragment);
            tv_loan_name = $(R.id.tv_loan_name);
            tv_time_limit = $(R.id.tv_time_limit);
            tv_loan_money = $(R.id.tv_loan_money);
            tv_loan_apr = $(R.id.tv_loan_apr);
            borrow_last_money = $(R.id.borrow_last_money);
            pb = $(R.id.tv_loan_progress);

        }

        @Override
        public void setData(LoanBean data) {

            DecimalFormat df = new DecimalFormat("0.00");
            tv_loan_name.setText(data.name+"");
            tv_loan_apr.setText(df.format(data.apr)+"%");
            if (data.is_day==1){
                tv_time_limit.setText(data.time_limit+"天");
            }else{
                tv_time_limit.setText(data.time_limit+"个月");
            }
            pb.setProgress(((int) (new Double(data.amount_invested )/new Double( data.account)*100)));
            //
            tv_loan_money.setText("总金额:"+data.account);
            borrow_last_money.setText(Double.parseDouble(data.account)-Double.parseDouble(data.amount_invested)+"");
            ObjectAnimator animator = ObjectAnimator.ofInt(pb, "progress", 0, ((int) (new Double(data.amount_invested)/new Double( data.account)*100)));
            animator.setDuration(3000);
            animator.start();
            super.setData(data);

        }
    }


}
